#!/bin/sh
#
# Copyright (C) 2000-2025 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run a simple backup of the Bacula build directory 
#   to /dev/null Of course, it's not possible to restore ;-)
#
TestName="backup-to-null"
JobName=backuptonull


. scripts/functions

# Not compatible with a backup to /dev/null
unset FORCE_DEDUP
unset FORCE_ALIGNED
unset FORCE_CLOUD
unset FORCE_SPOOL_DATA

scripts/cleanup
scripts/copy-fifo-confs

echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
rm -f ${cwd}/tmp/log1.out ${cwd}/tmp/log2.out
start_test


# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
@#setdebug level=200 storage=Dummy
label storage=Dummy volume=TestVolume001 slot=0 pool=Default
run job=$JobName yes
status storage=Dummy
@sleep 1
wait
@sleep 3
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=Dummy
stop_bacula

#
# Now do a second backup after making a few changes
#
touch ${cwd}/build/src/dird/*.c
echo "test test" > ${cwd}/build/src/dird/xxx

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log2.out
list volumes
run job=$JobName yes
wait
list volumes
@sleep 3
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=Dummy
stop_bacula

grep "^  Termination: *Backup OK" ${cwd}/tmp/log1.out 2>&1 >/dev/null
bstat=$?
grep "^  Termination: *Backup OK" ${cwd}/tmp/log2.out 2>&1 >/dev/null
dstat=$?

# not yet implemented
rstat=0

end_test
